use std::env;
use dotenv::dotenv;

#[derive(Clone)]
pub struct Config {
    pub database_url: String,
    pub jwt_secret: String,
    pub port: u16,
    pub deepseek_api_key: String,
    pub news_xml_path: String,
}

impl Config {
    pub fn from_env() -> Self {
        // 加载.env文件
        dotenv().ok();
        
        let database_url = env::var("DATABASE_URL")
            .unwrap_or_else(|_| "mysql://root:password@localhost/yqfx_db".to_string());

        println!("数据库连接: {}", database_url);
        
        let jwt_secret = env::var("JWT_SECRET")
            .unwrap_or_else(|_| "your-secret-key-here".to_string());
        
        let port = env::var("PORT")
            .unwrap_or_else(|_| "3000".to_string())
            .parse()
            .unwrap_or(3000);

        let deepseek_api_key = env::var("DEEPSEEK_API_KEY")
            .unwrap_or_else(|_| "your-deepseek-api-key".to_string());

        let news_xml_path = env::var("NEWS_XML_PATH")
            .unwrap_or_else(|_| {
                "../Datas/output_xml".to_string()
            });

        Self {
            database_url,
            jwt_secret,
            port,
            deepseek_api_key,
            news_xml_path,
        }
    }
} 